<%@ page language="java" import="java.util.*,entity.*,service.impl.*,service.* "  pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>search页面</title>
		<!--
        	作者：1107485571@qq.com
        	时间：2018-07-10
        	描述：引用bootstrap样式和js
        	版本说明：bootstrap 3.3.7   jquery3.3.1
        -->
		<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
		<script src="js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		
		<!--
        	作者：1107485571@qq.com
        	时间：2018-07-07
        	描述：引用额外的图标库
        -->
        <link rel="stylesheet" href="css/iconfont.css" />
        
        <!--
        	作者：1107485571@qq.com
        	时间：2018-07-07
        	描述：搜索页的css样式
        -->
        <link rel="stylesheet" href="css/search.css" />
		
	</head>
	<body>
		<%@ include file="header.jsp" %>
		
		<!-- 获得以关键字查询的结果list -->
		<% 
			if( request.getParameter("keyword") != null ) {
				List<Contest> contests = new ContestDAOImpl().queryAll(1, 10);	//没有任何方式的直接查询
				session.setAttribute("contests", contests);
				System.out.println("关键字为空，我搜到了"+contests.size()+"个比赛");
			} else { 																	//按关键字查询
				List<Contest> contests = new ContestDAOImpl().queryAllByKeyword( Integer.parseInt( request.getParameter("currentPage") ), 10, request.getParameter("searchKeyword"));
				session.setAttribute("contests", contests);
				System.out.println("关键字不为空，我搜到了"+contests.size()+"个比赛");
				for(int i=0; i<contests.size(); i++){
					Contest contest = contests.get(i);
					System.out.println(contest.getContestName());
				}
		 	}
		
			List<Contest> contests_byHot = new ContestDAOImpl().queryAllSortByHot(1, 10);	//按热度查询
			session.setAttribute("contests_byHot", contests_byHot);
			System.out.println("我按热度搜到了"+contests_byHot.size()+"个比赛");
			
			List<Contest> contests_byTime = new ContestDAOImpl().queryAllDefault(1, 10);	//按时间查询
			session.setAttribute("contests_byTime", contests_byTime);
			System.out.println("我按时间搜到了"+contests_byTime.size()+"个比赛");
			for(int i=0; i<contests_byTime.size(); i++){
				Contest contest = contests_byTime.get(i);
				System.out.println(contest.getContestName());
			}
		 %>
		<div class="container" id="mid_content">
			<div class="row clearfix">
				<div class="col-md-12 column">
					<div class="row clearfix">
						<div class="col-md-9 column" id="tab_mid">
							<div class="row clearfix">
								<div class="col-md-12 column" id="tab_mid_ul1">
									<ul class="nav nav-tabs">
										<li>
											 <a href="#">竞赛</a>
										</li>
										<li>
											 <a href="#">用户</a>
										</li>
										<li>
											 <a href="#">活动</a>
										</li>
										<li>
											 <a href="#">类别</a>
										</li>
									</ul>
								</div>
							</div>
							<div class="row clearfix">
								<div class="col-md-12 column" id="tab_mid_ul2">
									<ul class="list-unstyled">
										<c:forEach var="contest" items="${contests}">
											<li>
												<div class="test">
													<div id="contest_right">
														<span class="contest_baoming">立即报名</span>
														<span class="contest_jiezhi">距离报名截止还有 9 天</span>
														<a class="contest_xiangqing" href="contest_detail.jsp?contestName=${ contest.contestName }">竞赛详情>></a>
													</div>
													<div id="contest_title">
														<span class="signup_status">报名状态</span>
														<span class="signup_title"><a href="contest_detail.jsp?contestName=${ contest.contestName }">${ contest.contestName }</a></span>
													</div>
													<div id="contest_contents">
														<ul>
															<li>
																<span class="sp1">主办方&nbsp;&nbsp;&nbsp;&nbsp;</span>
																<span class="sp2">清华大学地球系统科学系</span>
															</li>
															<li>
																<span class="sp1">竞赛级别</span>
																<span class="sp2">国家级</span>
															</li>
															<li>
																<span class="sp1">报名时间</span>
																<span class="sp2">${ contest.contestStartTime }</span>
															</li>
															<li>
																<span class="sp1">比赛时间</span>
																<span class="sp2">${ contest.contestEndTime }</span>
															</li>
														</ul>
													</div>
												</div>
											</li>
										</c:forEach>
									</ul>
								</div>
							</div>
						</div>
						<div class="col-md-3 column">
							
							<div id="zuixinbisai_div">
								<span class="contest_new_title">
									<span style="margin-left: 9px;">最热比赛</span>
									<span style="color: red;font-size: 34px;font-weight: 10;" class="iconfont icon-huoyan"></span>
								</span>
								<ul class="list-unstyled contest_new">
									<% int cou = 1; %>
									<c:forEach var="contest" items="${contests_byHot}">
										<li>
											<div>
												<div class="contest_new_li_title"><a href="contest_detail.jsp?contestName=${contest.contestName}"><%=cou %>. ${ contest.contestName }</a></div>
												<span class="iconfont icon-huoyan" style="color:red;float:right;margin-top:-30px;margin-left:120px;">
													<span style="color:black;font-weight:800;">${ contest.hotDegree }</span>
												</span>
											</div>
										</li>
										<% cou++; %>
									</c:forEach>
								</ul>
							</div>
							
							<div id="zuixinbisai_div">
								<span class="contest_new_title">
									<span style="margin-left: 9px;">最新比赛</span>
									<span style="color: red;font-size: 34px;font-weight: 10;" class="iconfont icon-zuixin"></span>
								</span>
								<ul class="list-unstyled contest_new">
									<c:forEach var="contest" items="${contests_byTime}">
										<li>
											<div class="contest_new">
												<div class="contest_new_li_title"><a href="contest_detail.jsp?contestName=${contest.contestName}">${ contest.contestName }</a></div>
												<div class="contest_new_li_time">报名结束日期：<span>${ contest.signupEndTime }</span></div>
											</div>
											<span class="iconfont icon-zuixin" style="font-size:24px;color:red;float:right;margin-top:-35px;margin-right:20px;"></span>
										</li>
									</c:forEach>
								</ul>
							</div>
							
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<%@ include file="bottom.jsp" %>
	</body>
</html>
